import type {
  PaymentAdjustmentForm,
  PaymentAdjustmentQuery,
  PaymentAdjustmentVO,
} from './model';

import type { ID, IDS, PageResult } from '#/api/common';

import { commonExport } from '#/api/helper';
import { requestClient } from '#/api/request';

/**
 * 查询回款调整记录列表
 * @param params 查询参数
 * @returns 回款调整记录列表
 */
export function paymentAdjustmentList(params?: PaymentAdjustmentQuery) {
  return requestClient.get<PageResult<PaymentAdjustmentVO>>(
    '/hm/paymentAdjustment/list',
    {
      params,
    },
  );
}

/**
 * 查询回款调整记录详情
 * @param adjustmentId 调整记录ID
 * @returns 回款调整记录详情
 */
export function paymentAdjustmentInfo(adjustmentId: ID) {
  return requestClient.get<PaymentAdjustmentVO>(
    `/hm/paymentAdjustment/${adjustmentId}`,
  );
}

/**
 * 申请回款调整
 * @param data 申请表单
 * @returns void
 */
export function paymentAdjustmentApply(data: PaymentAdjustmentForm) {
  return requestClient.postWithMsg<void>(
    '/hm/paymentAdjustment/apply',
    data,
  );
}

/**
 * 审核（批准）回款调整
 * @param adjustmentId 调整记录ID
 * @param approveRemark 审核备注
 * @returns void
 */
export function paymentAdjustmentApprove(
  adjustmentId: ID,
  approveRemark?: string,
) {
  return requestClient.postWithMsg<void>(
    `/hm/paymentAdjustment/approve/${adjustmentId}`,
    null,
    {
      params: { approveRemark },
    },
  );
}

/**
 * 驳回回款调整
 * @param adjustmentId 调整记录ID
 * @param rejectReason 驳回原因
 * @returns void
 */
export function paymentAdjustmentReject(
  adjustmentId: ID,
  rejectReason: string,
) {
  return requestClient.postWithMsg<void>(
    `/hm/paymentAdjustment/reject/${adjustmentId}`,
    null,
    {
      params: { rejectReason },
    },
  );
}

/**
 * 取消回款调整
 * @param adjustmentId 调整记录ID
 * @returns void
 */
export function paymentAdjustmentCancel(adjustmentId: ID) {
  return requestClient.postWithMsg<void>(
    `/hm/paymentAdjustment/cancel/${adjustmentId}`,
  );
}

/**
 * 删除回款调整记录
 * @param adjustmentIds 调整记录ID数组
 * @returns void
 */
export function paymentAdjustmentRemove(adjustmentIds: ID | IDS) {
  return requestClient.deleteWithMsg<void>(
    `/hm/paymentAdjustment/${adjustmentIds}`,
  );
}

/**
 * 导出回款调整记录列表
 * @param params 查询参数
 * @returns 导出文件
 */
export function paymentAdjustmentExport(params?: PaymentAdjustmentQuery) {
  return commonExport('/hm/paymentAdjustment/export', params ?? {});
}
